<?php
error_reporting(E_ALL ^ E_NOTICE);
include("mpdf/mpdf.php");

if ($_GET == null || $_GET['code'] == null) {
    echo "Lỗi code!";
} else {
    $codeId = $_GET['code'];
    $fileName= base64_decode(base64_decode($codeId));
    if (!file_exists($fileName) || !is_file($fileName)) {
        echo "Tập tin không chính xác.";
    } else {
        //print_r($_POST);
        $pdfFile = $fileName;
        $mpdf=new mPDF();
        $mpdf->SetImportUse();
        
        //$stylesheet = file_get_contents('main.css');
        //$mpdf->WriteHTML($stylesheet,1);
        
        $page[][];
        $count=0;
        $pageCount = $mpdf->SetSourceFile($pdfFile);
        for ($i=0;$i<$pageCount;$i++) {
            for ($j=0; $i < $_POST.length; $j++) {
                $id = $_POST[$j];
                $p = split("-", $id);
                $thisPage = $p[1];
                if ($thisPage == $i)
                    $page[$i][$count++] = $id;
            }
        }

        for ($i=1;$i<=$pageCount;$i++) {
                $temp = $mpdf->ImportPage($i);
                $mpdf->AddPage();
                $mpdf->UseTemplate($temp);
                $index = $i - 1;
                $mpdf->WriteHTML(print_r ($_POST));
                switch ($i) {
                    case 1:
                        $mpdf->WriteHTML('<div style="position: absolute; left: 654px; top: 0px;color:yellow;">văn bản mặc định</div>');
                        break;
                    default:
                        $mpdf->WriteHTML('<div style="position: absolute; left: 654px; top: 0px;color:yellow;">văn bản mặc định</div>');
            }
        }
        $mpdf->Output($pdfFile, 'I');
    }
}
setcookie ("fileDownloadToken", $downloadTokenValue);
exit;

?>
